﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NHibernate;
using ZLCMS.Business.Util;
using ZLCMS.Data.Model;

namespace ZLCMS.Web.SystemManage.Basics.Shop.ShippingProduct
{
    public partial class ShippingProductList : System.Web.UI.Page
    {
        protected ZLCMS.Business.DwzFrame.FrameHelper _framePage;

        protected void Page_Load(object sender, EventArgs e)
        {
            _framePage = new ZLCMS.Business.DwzFrame.FrameHelper(this);
            
            //设置分页大小
            int pageSize = _framePage.IsAjaxPagerPostBack ? _framePage.PageSize : 20;

            //设置页码
            int pageIndex = _framePage.IsAjaxPagerPostBack ? _framePage.PageIndex : 1;

            string sql = " from ShopOrderShippingInfo where OwnerAccount=:acc ";
            if (!string.IsNullOrEmpty(Request["orderno"]))
            {
                sql += " and OrderNo=:no ";
            }
            using (NHibernate.ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                IQuery query = session.CreateQuery(sql).SetParameter("acc", UserKit.GetUserAccountFailLogin());
                if (!string.IsNullOrEmpty(Request["orderno"]))
                {
                    query.SetParameter("no", Request["orderno"]);
                }
                //导出excel
                if (!string.IsNullOrEmpty(Request["exportexcel"]))
                {

                }
                else
                {
                    //设置数据源
                    repeater1.DataSource = query.SetFirstResult((pageIndex - 1) * pageSize)
                        .SetMaxResults(pageSize)
                        .List<ShopOrderShippingInfo>();
                    repeater1.DataBind();

                    query = session.CreateQuery("select count(*) " + sql).SetParameter("acc", UserKit.GetUserAccountFailLogin());
                    if (!string.IsNullOrEmpty(Request["orderno"]))
                    {
                        query.SetParameter("no", Request["orderno"]);
                    }
                    //设置记录总数
                    _framePage.RecordCount = Convert.ToInt32(query.UniqueResult());

                }
            }

        }


        //protected void ExportExcel()
        //{
        //    using (NHibernate.ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
        //    {
        //        ICriteria criteria = session.CreateCriteria<--YourObject-->();
        //        SetupCondition(ref criteria);
        //        criteria.AddOrder(Order.Desc("Id"));

        //        IList<--YourObject--> list = criteria.List<--YourObject-->();


        //        StringWriter sw = new StringWriter();
        //        sw.WriteLine("列1\t列2\t列3\t列4");
        //        foreach (--YourObject-- item in list)
        //        {
        //            sw.WriteLine("'" + item.CheckCode + "\t" + item.OperatorId + "\t" + item.UseDate + "\t" + ParamKit.GetValue("YesNo_10", item.Status, ""));
        //        }
        //        sw.Close();

        //        OutputKit.OutputExcel(Response, sw);
        //    }
        //}
    }
}